import state from "../cart/state"

export default{
	namespaced:true,
	state:()=>({
		address:JSON.parse(uni.getStorageSync('address')|| '{}'),
		token:uni.getStorageSync('token')||'',
		userInfo:JSON.parse(uni.getStorageSync('userInfo')||'{}'),
		redirectinfo:null
	}),
	mutations:{
		// 修改地址
		updateAddress(state,address){
			state.address=address
			this.commit('user/saveAddressToStorage')
		},
		//将地址保存到Storage
		saveAddressToStorage(state){
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		//修改用户信息
		updateUserInfo(state,userInfo){
			state.userInfo=userInfo
			this.commit('user/saveuserInfoToStrage')
		},
		//将用户信息保存到Storage
		saveuserInfoToStrage(state){
			uni.setStorageSync('userInfo',JSON.stringify(state.userInfo))
		},
		updateToken(state,token){
			state.token=token
			this.commit('user/saveTokenToStrage')
		},
		saveTokenToStrage(state){
			uni.setStorageSync('token',state.token)
		},
		updateRedirectInfo(state,redirect){
			state.redirectinfo=redirect
			//console.log(state.redirectinfo)
		}
	},
	getters:{
		addstr(state){
			if(!state.address.provinceName){
				return ''
			}			
			return state.address.provinceName+state.address.cityName+state.address.countyName+state.address.detailInfo
		}
	}
}